package com.api.aiyh_pcn.patentWall.controller;

import aiyh.utils.ApiResult;
import aiyh.utils.Util;
import com.api.aiyh_pcn.patentWall.dto.FilterWhere;
import com.api.aiyh_pcn.patentWall.service.PatentWallService;
import com.api.aiyh_pcn.patentWall.vo.PatentVO;
import com.api.aiyh_pcn.patentWall.vo.SearchInputVO;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.Map;

/**
 * @author EBU7-dev1-ayh
 * @create 2021/11/25 0025 15:18
 * 专利墙请求入口
 */


@Path("/patten/")
public class PatentWallController {
	private  final PatentWallService patentWallService = new PatentWallService();

	@Path("/getSearchList/{prefix}")
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public String getPatentList(@Context HttpServletRequest request, @Context HttpServletResponse response,
	                            @PathParam("prefix") String prefix){
		User user = HrmUserVarify.getUser(request, response);
		int languageId = user.getLanguage();
		List<SearchInputVO> result = patentWallService.getSearchList(prefix,languageId);
		return ApiResult.success(result);
	}

	@Path("/getList/{prefix}")
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	public String getPatentList(@RequestBody List<FilterWhere> filterWheres, @PathParam("prefix") String prefix){
		List<PatentVO> result = patentWallService.getList(filterWheres,prefix);
		return ApiResult.success(result);
	}

	@Path("/clearConf")
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public String clearPatentWallConf(){
		patentWallService.clearPatentWallConf();
		patentWallService.clearPatentWallSerachConf();
		return ApiResult.success("清除配置缓存成功！");
	}
}
